﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Corsat.Library.DataManager
{
    public static partial class Main
    {
        #region Private Methods
        #endregion

        #region Public Methods
        public static void AddParentAndChildrenItems(string ParentItem, Category ParentCategory, List<string> ChildItems, Category ChildCategory)
        {
            command.CommandText =
                @"

Declare @ParentItemId int
INSERT INTO ITEMS 
(ItemName, CategoryId)
values
(N'" + ParentItem + "'," + Convert.ToInt32(ParentCategory).ToString() + @")

   SET @ParentItemId = @@IDENTITY
";
            for (int i = 0; i < ChildItems.Count; i++)
            {
                command.CommandText +=
                    @"

Insert into Items
(ItemName, CategoryId, ParentItemId)
values
(N'"+ChildItems[i]+"',"+Convert.ToInt32(ChildCategory).ToString()+",@ParentItemId)";
            }

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        #endregion
    }
}
